/*************************************************************************
	> File Name: 003.邻接表.cpp
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 二  5/18 16:07:39 2021
 ************************************************************************/

#include <iostream>
#include <vector>
#include <utility>
using namespace std;


int n, m; // n个点，m条边
int main() {
    cin >> n >> m;
    //初始化边集
    vector<vector<pair<int, int>>> edges(n + 1, vector<pair<int, int>>{});
    for (int i = 0; i < m; i++) {
        int s, e, v;
        cin >> s >> e >> v;
        edges[s].push_back(make_pair(e, v)); //终点和权值组成的，假设为有向边
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " : ";
        for (int j = 0; j < edges[i].size(); j++) {
            cout << "{" << edges[i][j].first << ", " << edges[i][j].second << "}";
        }
        cout << endl;
    }


    return 0;
}
